<template>
    <vol-box
      :lazy="true"
      v-model="model"
      title="选择售后发货单"
      :height="400"
      :width="1200"
      :padding="5"
      :onModelClose="onModelClose"
    >
      <div>
        <after_deliveryCom ref="after_deliveryCom"></after_deliveryCom>
      </div>
      <template #footer>
        <div>
          <el-button type="primary" size="small" @click="onSelect"
            >确认</el-button
          >
        </div>
      </template>
    </vol-box>
  </template>
  <script>
  import VolBox from "@/components/basic/VolBox.vue";
  import after_deliveryCom from "@/views/aftersaleinfo/after_delivery/q_after_delivery.vue";
  //这里使用的vue2语法，也可以写成vue3语法
  export default {
    components: {
      "vol-box": VolBox,
      after_deliveryCom,
    },
    data() {
      return {
        model: false,
      };
    },
    methods: {
      async onModelClose() {
        await this.$refs.after_deliveryCom.$refs.grid.search();//触发页面的查询
      },
      open(WHSE_no) {
        this.model = true;
        let setIntervalTiem = setInterval(() => {
          if (this.$refs.after_deliveryCom) {
            clearInterval(setIntervalTiem);
            this.$refs.after_deliveryCom.searchFormFields.AuditStatus = "1";//设置默认查询参数
            if(this.$route.path == "/q_after_return" ){
              this.$refs.after_deliveryCom.searchFormFields.WHSE_no = WHSE_no;
              this.$refs.after_deliveryCom.searchFormOptions.forEach(item => {
                item.forEach(x => {
                  if(x.field == "WHSE_no"){
                    x.disabled = true
                  }
                })
             })
            }
            this.$refs.after_deliveryCom.$refs.grid.search();//触发页面的查询
          }
        }, 100);
      },
  
      onSelect() {
        let rowObj = this.$refs.after_deliveryCom.$refs.grid.getSelectRows();
        if (rowObj.length!=1) {
            this.base.ElMessageFn("请选择一条数据");
          return (this.model = true);
        }
        let AuditStatusSome = rowObj.some((item) => item.AuditStatus != 1);
        if (AuditStatusSome) {
            this.base.ElMessageFn("请勿选择审核未通过单据");
          return;
        }
        this.$emit("parentCall", ($parent) => {
          if(this.$route.path == "/q_after_return"){
              $parent.editFormFields.After_delivery_sub =
              rowObj[0].Voucher_sub;//编码
              $parent.editFormFields.Client_name =
              rowObj[0].Client_name;
              $parent.editFormFields.After_delivery = rowObj[0].After_delivery;//ID
            }
        });
        this.onModelClose();
        return (this.model = false);
      },
    },
  };
  </script>